﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class WebSite_QuestionControl : System.Web.UI.UserControl
{
    public string Title;
    public int TitleId;
    public int Count;
    public Dictionary<string, int> Content;
    public WebSite_QuestionControl()
    {
        Title = "";
        TitleId = 0;
        Count = 1;
        Content = new Dictionary<string, int>();
    }
    public WebSite_QuestionControl(string title,int Id,int count,Dictionary<string, int> content)
    {
        Title = title;
        TitleId = Id;
        Count = count;
        Content = content;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Title!=null)
        {
            QuestionTitleLabel.Text = TitleId.ToString() + ". " + Title;
        }
        QustionContentLabel.Text= ShowContent();
    }
    private string ShowContent()
    {
        string strContent;
        if (Content==null)
        {
            return "";
        }
        char Index = 'A';
        strContent="";
        if (Count == 0)
        {
            Count = 1;
        }
        foreach (KeyValuePair<string, int> element in Content)
        {
            strContent = "<div class=\"pitem_clearfix\">";
            strContent += "<div class=\"psubject\">" + Index+". "+element.Key + ": </div>";
            strContent += "<div class=\"pbarbg\">" + "<div class=\"bar\" style=\"width:" + (element.Value * 100 / Count).ToString() + "px;\">"+"</div></div>";
            strContent += "<div class=\"precord\">" + element.Value.ToString() + " (" + (element.Value * 100 / Count).ToString() + ")</div></div>\n";
            Index=(char)((int)Index+1);
        }
        return strContent;       
    }
}
